<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: 唐僧骑马洗头
  Date: 2021/8/15
  Time: 13:33
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>访问信息查询</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/semantic-ui/2.2.10/semantic.min.css">
    <script src="${pageContext.request.contextPath}/jQuery/jquery-3.6.0.js"></script>
</head>
<body>
<div class="ui container">
    <form class="ui form" action="${pageContext.request.contextPath}/student/admin/visitMessage">
        <div class="field">
            <label>Name</label>
            <div class="two fields">
                <div class="field ">
                    <input type="text" name="shipping01" placeholder="姓" >
                </div>
                <div class="field ">
                    <input type="text" name="shipping02" placeholder="名" >
                </div>
            </div>
        </div>
        <div class="two fields">
            <div class="field">
                <label>Sex</label>
                <input type="radio" name="sex" tabindex="0" class="hidden" value="男"> 男
                <input type="radio" name="sex" tabindex="0" class="hidden" value="女" style="margin-left: 50px">女
            </div>
            <div class="field">
                <label>Tel</label>
                <input type="text" name="tel" placeholder="请输入电话号码.......">
            </div>
        </div>
        <div class="two fields">
            <div class="field">
                <label>To-Visit</label>
                <select class="ui fluid dropdown" id="myselect" name="build_name" onchange="changes()">
                    <option value="">--请选择--</option>
                    <c:forEach items="${builds}" var="one">
                        <option  value="${one.build_Name}">${one.build_Name}</option>
                    </c:forEach>
                </select>
            </div>
            <div class="field">
                <label>RoomId</label>
                <select class="ui fluid dropdown" name="room_id" id="room">
                    <option value="">--请选择--</option>
                </select>
            </div>
        </div>
        <div class="fields">
            <div class="thirteen wide field">
                <label>Thing</label>
                <input type="text" name="things" placeholder="请输入原因.....">
            </div>
            <div class="three wide field">
                <label>Time</label>
                <input type="text" name="times" placeholder="请输入拜访时间......" >
            </div>
        </div>
        <button class="ui submit button" tabindex="0">Search</button>
    </form>

    <div id="userError" class="ui mini negative message" style="display: none !important;">关于此信息没有记录，请输入有效信息.....</div>

    <script>

        var str = '${message}';
        console.log("===>"+str);
        if(str =="1"){
            document.getElementById("userError").style.display="";//隐藏
        }
        document.getElementById("userError").style.display="none";//显示

        function changes() {
            var options=$("#myselect option:selected").text();

            console.log(options)
            $.ajax({
                url: "${pageContext.request.contextPath}/student/roomId?build_name="+options,
                dataType: "json",
                method: "post",
                success: function (data) {
                    console.log(data)
                    var str = JSON.stringify(data)
                    $.each(JSON.parse(str),function(i,result) {
                        console.log("====>"+result.toString())
                        var item="<option value="+result.dor_Id+">"+result.dor_Id+"</option>";
                        $("#room").append(item);
                    });
                },
                error:function (err) {
                    console.log("fal")
                }
            })
        }
    </script>
</div>
</body>
</html>
